/*
 ============================================================================
 Name        : CC_P1.java
 Author      : 
 Partner     : 
 Copyright   : Your copyright notice
 Description : Cloud Computing Project 1
 ============================================================================
 */

import java.io.*;
import java.util.*;

public class bootCloud {
	public static void main(String[] args) throws IOException {

	    //read DataCenter list
	    ArrayList<DataCenter> dcList = buildDcList();
	    //read VM list
	    ArrayList<VirtualMachine> vmTypeList = buildVmList();
	    
	    //start the data center	
	    int portID=5000;
	    String name="Mercury Cloud Provider";
	    Cloud C = new Cloud(name,dcList,vmTypeList,portID);
	    System.out.println("\n\n"+C.getName() + " is now online on port "+portID);
	    System.out.println(C.getNumServers() + " servers on "+C.getNumDataCenters()+" datacenters have been launched.\n");
	    new Thread(C).start();

	}

	public static ArrayList<DataCenter> buildDcList() {
		
	    ArrayList<DataCenter> dcList = new ArrayList<DataCenter>();
	    
	    String name="New York";
	    double lat=40+47/60;
	    double lon=73+58/60;
	    ArrayList<PhysicalMachine> pmList= buildPmList();
	    
	    DataCenter dc= new DataCenter(name,0,lat,lon,pmList);
	    dcList.add(dc);
	    
	    return dcList;
	
	}

	public static ArrayList<PhysicalMachine> buildPmList() {

	    ArrayList<PhysicalMachine> pmList = new ArrayList<PhysicalMachine>();

	    // Create list of physical machines in the data centers
	    int nPm=5;
	    for (int i=0; i<nPm; i++) {		
	    	PhysicalMachine pm = new PhysicalMachine();
	    	pm.setvcpu(18);
	    	pm.setmemory(48);
	    	pm.setdisk(5000);
	    	pm.setlan(10000);
	    	pm.setid(i);
	    	pmList.add(pm);
	    }

	    return pmList;

	}
	
	public static ArrayList<VirtualMachine> buildVmList() {

	    ArrayList<VirtualMachine> vmList = new ArrayList<VirtualMachine>();
	    
	    // Create Virtual Machines
	    VirtualMachine vm1 = new VirtualMachine();
	    vm1.setvcpu(1);
	    vm1.setmemory(1);
	    vm1.setdisk(10);
	    vm1.setlan(50);
	    vm1.setprice(0.10);
	    vm1.setname("Tiny");
	    vmList.add(vm1);

	    VirtualMachine vm2 = new VirtualMachine();
	    vm2.setvcpu(2);
	    vm2.setmemory(4);
	    vm2.setdisk(20);
	    vm2.setlan(50);
	    vm2.setprice(0.15);
	    vm2.setname("Small");
	    vmList.add(vm2);
	    
	    VirtualMachine vm3 = new VirtualMachine();
	    vm3.setvcpu(4);
	    vm3.setmemory(8);
	    vm3.setdisk(50);
	    vm3.setlan(100);
	    vm3.setprice(0.20);
	    vm3.setname("Medium");
	    vmList.add(vm3);
	    
	    VirtualMachine vm4 = new VirtualMachine();
	    vm4.setvcpu(8);
	    vm4.setmemory(16);
	    vm4.setdisk(100);
	    vm4.setlan(100);
	    vm4.setprice(0.30);
	    vm4.setname("Large");
	    vmList.add(vm4);
	    
	    VirtualMachine vm5 = new VirtualMachine();
	    vm5.setvcpu(16);
	    vm5.setmemory(32);
	    vm5.setdisk(500);
	    vm5.setlan(1000);
	    vm5.setprice(0.50);
	    vm5.setname("Huge");
	    vmList.add(vm5);
	    return vmList;
	}
}